#include "Oled.h"
#include <Arduino.h>
#include <U8g2lib.h>

// I2C 版本的 SSD1306 显示屏构造函数
U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0, 6, 5, U8X8_PIN_NONE);

const uint8_t full_wifi[] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x00, 0xc0, 0xc3, 0x03, 0x70, 
	0x00, 0x0e, 0x38, 0x3e, 0x1c, 0x9c, 0xff, 0x19, 0xc0, 0x81, 0x03, 0xe0, 0x00, 0x07, 0x20, 0x7e, 
	0x04, 0x00, 0xf7, 0x00, 0x80, 0x81, 0x01, 0x80, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x3c, 0x00, 
	0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const uint8_t middle_wifi[] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x3e, 0x00, 0x80, 0xff, 0x01, 0xc0, 0x81, 0x03, 0xe0, 0x00, 0x07, 0x20, 0x7e, 
	0x04, 0x00, 0xf7, 0x00, 0x80, 0x81, 0x01, 0x80, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x3c, 0x00, 
	0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const uint8_t low_wifi[] PROGMEM = {
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7e, 
	0x00, 0x00, 0xef, 0x00, 0x01, 0x81, 0x80, 0x01, 0x00, 0x80, 0x00, 0x18, 0x00, 0x00, 0x3c, 0x00, 
	0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

const uint8_t command_logo[] PROGMEM = {
  0xff, 0xff, 0xff, 0x03, 0x00, 0xf0, 0x03, 0x00, 0xe0, 0x49, 0x01, 0xe0, 0x01, 0x00, 0xe0, 0xf9, 
	0xff, 0xef, 0xf9, 0xff, 0xef, 0xb9, 0xff, 0xef, 0x39, 0xff, 0xef, 0xf9, 0xfc, 0xef, 0xf9, 0x33, 
	0xee, 0xf9, 0xf3, 0xef, 0xf9, 0xfc, 0xef, 0x39, 0xff, 0xef, 0xf9, 0xff, 0xef, 0xf9, 0xff, 0xef, 
	0xf9, 0xff, 0xef, 0x03, 0x00, 0xe0, 0xff, 0xff, 0xff
};

const uint8_t face[] PROGMEM = {
  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
	0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 
	0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
	0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xdf, 0xff, 0xff, 0xff, 
	0xff, 0xff, 0x3f, 0xff, 0xff, 0x01, 0xfe, 0xff, 0x0f, 0xf0, 0xff, 0x3f, 0xff, 0xff, 0x3c, 0xfc, 
	0xff, 0xc7, 0xe7, 0xff,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0xff, 0xff, 0xff, 0xff, 0xff, 
	0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 
	0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 
	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 
	0x3f
};

void initOLed(){
    u8g2.begin();
	u8g2.setFlipMode(1); // 启用180度旋转
	u8g2.enableUTF8Print();
    u8g2.setContrast(250);
}

void showWifiLink(){
    u8g2.clearBuffer();
    u8g2.drawXBM(0+30,0+14, 24, 19, full_wifi);
    u8g2.setCursor(0+30, 30+14);
	u8g2.setFont(u8g2_font_wqy12_t_gb2312a);
    u8g2.print("连接中...");
    u8g2.sendBuffer();
}

//显示卡通眼睛
void showCartoonEyes() {
    u8g2.clearBuffer();
    u8g2.drawXBM(0+30,0+14, 70, 41, face);
    u8g2.sendBuffer();
}
//显示指令logo
void showCommandLogo() {
    u8g2.clearBuffer();
    u8g2.drawXBM(0+30,0+14, 24, 19, command_logo);
}
//显示wifi logo
void showWifiLogo(String level) {
    u8g2.clearBuffer();
    if (level.equals("full_wifi")) {
        u8g2.drawXBM(0+30,0+14, 24, 19, full_wifi);
    } else if (level.equals("middle_wifi")) {
        u8g2.drawXBM(0+30,0+14, 24, 19, middle_wifi);
    } else if (level.equals("low_wifi")) {
       u8g2.drawXBM(0+30,0+14, 24, 19, low_wifi);
    }
}


//显示文字
void showLiveTxt(int x,int y,const String &str) {
    u8g2.clearBuffer();
    u8g2.setCursor(x+30, y+14);
	u8g2.setFont(u8g2_font_5x7_tr);
    u8g2.print(str.c_str());
    u8g2.sendBuffer();
}

void showTxt(int x,int y,const String &str) {
    u8g2.setCursor(x+30, y+14);
	u8g2.setFont(u8g2_font_5x7_tr);
    u8g2.print(str.c_str());
    u8g2.sendBuffer();
}